package sebastiankerckhof.scene.transformation;

import java.util.Stack;

import sebastiankerckhof.math.Matrix4f;

public class TransformationStack {

	Stack<Transformation> stack = new Stack<Transformation>();

	Matrix4f N;
	
	public TransformationStack(){
	}
	
	public void push(Transformation m){
		stack.push(m);
	}
	
	public Matrix4f pop(){
		Matrix4f top = peek();
		stack.pop();
		return top;
	}
	
	public Matrix4f peekNormal(){
		return peekNormalStep(1.0f);
	}
	
	public Matrix4f peekNormalStep(float step){
		Matrix4f m = new Matrix4f();
		m.setIdentity();
		for(Transformation t : stack)
			m = t.getInvertStep(step).multiply(m);
		
		return m.transpose();
	}
	
	public Matrix4f peek(){
		return peekStep(1.0f);
	}
	
	public Matrix4f peekStep(float step){
		Matrix4f m = new Matrix4f();
		m.setIdentity();
		
		for(Transformation t : stack)
			m = m.multiply(t.getStep(step));
		
		return m;
	}
	
	public int size(){
		return stack.size();
	}
	
	public TransformationStack clone(){
		TransformationStack clone = new TransformationStack();
		for(Transformation t : stack)
			clone.push(t);
		
		return clone;
	}
}
